﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace EfficientTest
{
    class Program
    {
        static void Main(string[] args)
        {
            int length = 1000000;
            HashSet<int> hasSet = new HashSet<int>();
            Dictionary<int,int> ditionary = new Dictionary<int,int>();
            List<int> list = new List<int>();
            List<int> list1 = new List<int>();
            Stopwatch stopwatch = new Stopwatch();

            //--------添加运行时间测试------------
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                hasSet.Add(i);
            }
            stopwatch.Stop();
            Console.WriteLine($"添加运行时间HasSet:{stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                ditionary.Add(i,i);
            }
            stopwatch.Stop();
            Console.WriteLine($"添加运行时间Dictionary:{stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                list.Add(i);
                list1.Add(i);
            }
            stopwatch.Stop();
            Console.WriteLine($"添加运行时间List:{stopwatch.ElapsedMilliseconds}");
            //--------添加运行时间测试------------


            //--------遍历运行时间测试------------
            stopwatch.Restart();
            foreach (int i in hasSet)
            {

            }
            stopwatch.Stop();
            Console.WriteLine($"遍历运行时间HasSet:{stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            foreach (KeyValuePair<int,int> i in ditionary)
            {

            }
            stopwatch.Stop();
            Console.WriteLine($"遍历运行时间Dictionary:{stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            foreach (int i in list)
            {

            }
            stopwatch.Stop();
            Console.WriteLine($"遍历运行时间List:{stopwatch.ElapsedMilliseconds}");
            //--------遍历运行时间测试------------

            ///--------包含运行时间测试------------
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                hasSet.Contains(i);
            }
            stopwatch.Stop();
            Console.WriteLine($"包含运行时间HasSet:{stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                ditionary.ContainsKey(i);
            }
            stopwatch.Stop();
            Console.WriteLine($"包含运行时间Dictionary:{stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                list.Contains(i);
            }
            stopwatch.Stop();
            Console.WriteLine($"包含运行时间List:{stopwatch.ElapsedMilliseconds}");
            ///--------包含运行时间测试------------

            //--------移除运行时间测试------------
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                hasSet.Remove(i);
            }
            stopwatch.Stop();
            Console.WriteLine($"移除运行时间HasSet:{stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                ditionary.Remove(i);
            }
            stopwatch.Stop();
            Console.WriteLine($"移除运行时间Dictionary:{stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            for (int i = 0; i < length; i++)
            {
                list.Remove(list1[i]);
            }
            stopwatch.Stop();
            Console.WriteLine($"移除运行时间List:{stopwatch.ElapsedMilliseconds}");
            //--------移除运行时间测试------------
            
            Console.ReadKey();
        }
    }
}
